<template>
  <div>
    <template v-if="item.fieldName === 'customerName'">
      <template>
        <a
          href=""
          class="view-detail-btn task-list-numbering"
          @click.stop.prevent="openProductTab(scope.row, false)"
        >
          {{ scope.row[item.fieldName] }}
        </a>
      </template>
    </template>
    <template v-else-if="item.fieldName === 'name'">
      <template>
        <a
          href=""
          class="view-detail-btn task-list-numbering"
          @click.stop.prevent="openProductTab(scope.row, true)"
        >
          {{ scope.row[item.fieldName] }}
        </a>
      </template>
    </template>
    <template v-else-if="item.fieldName === 'createTime'">
      {{ scope.row[item.fieldName] | formatTime}}
    </template>
    <template v-else>
      {{ scope.row[item.fieldName] }}
    </template>
  </div>
</template>

<script>
import { formatDate } from 'pub-bbx-utils'
import { openAccurateTab } from '@src/util/platform'
import { PageRoutesTypeEnum } from 'pub-bbx-global/pageType/dist/enum/PageRoutesEnum'
export default {
  props: {
    item: {
      type: Object,
      default: () => ({}),
    },
    scope: {
      type: Object,
      default: () => ({}),
    },
  },
  filters: {
    formatStatus(value) {
      return value.join(',')
    },
    formatTagList(value) {
      return value.map(item => item.tagName).join(',')
    },
    formatTime(val) {
      return formatDate(val)
    }
  },
  methods: {
    openProductTab({id}, isProductPage) {
      if (!id) return;
      let fromId = window.frameElement.getAttribute('id');
      let data = {
        type:PageRoutesTypeEnum.PageProductView,
        key:id
      }
      if(!isProductPage) {
        data.type =  PageRoutesTypeEnum.PageCustomerView
      }
      openAccurateTab({
        ...data,
        params:'noHistory=1',
        fromId
      })
    
     
    },
  }
};
</script>

<style lang="scss" scoped>
</style>